// ./inc/GUIEditorDlg.h : header file
//

#pragma once
#include "afxcmn.h"

#include <DSTreeCtrl.h>
#include <DSCallBackT.h>
#include <vector>

#include "AStar.h"
#include "DSGLDrawer.h"
#include "DSRoleSetBased.h"
#include "DSEnvItemInfo.h"

class CDSEnvItemInfo;
class CDSRoleSetBased;

typedef struct
{
	CString cstrFilePath;
	CBitmap *pBitMap;
}CDSItemIcon;


// CGUIEditorDlg dialog
class CGUIEditorDlg : public CDialog
{
// Construction
public:
	CGUIEditorDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_GUIEDITOR_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
//============== User Defined ==================
//*********** Define ****************
protected:
	typedef enum
	{
		CALBAK_ID_ENV_ITEM_TREE = 101,
		CALBAK_ID_ROLE_SET_TREE
	}DSCallBackID;

	typedef enum
	{
		MAP_OBJ_TYPE_ENV_ITEM = 1001,
		MAP_OBJ_TYPE_ROLE
	}DSMapObjType;

	typedef struct
	{
		CDSRoleSetBased::CDSRoleAttribs cdsRoleAttribs;
		CDSEnvItemInfo::CDSEnvItemData cdsEnvItemData;
		CDSAStarCell cdsMapInfo;
		int nType;											//Object type = env item or role
		int nReserved;
	}CDSMapObj;
//*********** Data Member ************
protected:
//GL
	CDSGLDrawer m_glWindow;

//UI
	HTREEITEM m_hRoleSettingTree;
	CImageList m_cImageList;
	CImageList m_cImageListColor;
	CString m_cstrCaption;
	std::vector<COLORREF> m_vclr16ColorsTable;
	std::vector<CDSItemIcon> m_vcdsItemIcon;
	CString m_cstrPicDirPath;

//Others
//	Right button menu
	CDSCallbackT<CGUIEditorDlg> m_cdsMouseOperationCallBackT;
	CMenu *m_pRClkMenu;
	HMENU m_hRClkMenu;
	std::vector<CDSMapObj> m_vcdsMapObjList;

//A Star
	CAStar m_cdsAStar;

//*********** Member Function ************
protected:
	void BuildDefault16ColorsTable(void);
	void BuildDefaultEnvironmentItems(CString cstrFileDir);
	void BuildDefaultRoleSetting(CString cstrFileDir);
	unsigned int GetTreeRootNum(CDSTreeCtrl *pcdsTree);
	CString GetSettingFilePath(void);
	BOOL SaveSetting(const char* szFilePath);
	BOOL LoadSetting(const char* szFilePath);
	BOOL AddItemPic(const char* szFilePath, COLORREF clrMask = RGB(0, 0, 0));
	BOOL RemoveItemPic(const char* szFilePath);
	void RefreshTreeIcon(CDSTreeCtrl *pTree);
	void RefreshTreeIcon(void);
	void AddMapObject(int nType, void *lpData);
	void UpdateMapObject(int nType, void *lpData);
	void RemoveMapObject(int nType, void *lpData);
	void AddEnvItem2TreeCtrl(CDSEnvItemInfo *pcdsEnvItemInfo);
	void AddRole2TreeCtrl(CDSRoleSetBased *pcdsRole);
	void CleanTreeItem(CDSTreeCtrl *pTree);
	int GetPicIconID(const char* szFilePath);

	bool OnUserClickRBtnOnListCallBack(void* pID, void* pData);
	BOOL OnRightButtonClick(int *pCallBackEventID, CDSTreeCtrl *pTargetTree, int nMenuID);
	BOOL OnLeftButtonDown(int *pCallBackEventID, CDSTreeCtrl *pTargetTree);
	BOOL OnDragTreeItemOnGLView(CDSCallBack_LDragOnGLView *pLDragOnGLView);

//================ UI =======================
protected:
//Tree
	//CTreeCtrl m_treEnvItems;		// Tree of environment items
	CDSTreeCtrl m_treEnvItems;		// Tree of environment items
	//CTreeCtrl m_treRolesSetting;	// Tree of setting of Roles
	CDSTreeCtrl m_treRolesSetting;	// Tree of setting of Roles


	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

public:
//============ User Defined =================
//System menu
	afx_msg void OnSaveFile(void);
	afx_msg void OnLoadFile(void);
	afx_msg void OnExit(void);

//Right click menu
	afx_msg void OnAddEnvironmentItem(void);
	afx_msg void OnEditEnvironmentItem(void);
	afx_msg void OnRemoveEnvironmentItem(void);

	afx_msg void OnAddRole(void);
	afx_msg void OnEditRole(void);
	afx_msg void OnRemoveRole(void);

//============= MFC =====================
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);

	virtual BOOL PreTranslateMessage(MSG* pMsg);
public:
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
};
